import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;


public class ExpressionTest {
    // 测试加法子类
    @Test
    public void testAddExpression() {
        AbstractExpression addExp = new AddExpression(3, 5); // 父类引用指向子类
        assertTrue(addExp.isValid());
        assertEquals(8.0, addExp.getResult(), 0.001);
        assertEquals("3.0 + 5.0 = 8.0", addExp.getExpression());

        // 测试小数加法
        AbstractExpression addExp2 = new AddExpression(2.5, 1.5);
        assertEquals(4.0, addExp2.getResult(), 0.001);
    }

    // 测试减法子类
    @Test
    public void testSubtractExpression() {
        AbstractExpression subExp = new SubtractExpression(10, 4);
        assertTrue(subExp.isValid());
        assertEquals(6.0, subExp.getResult(), 0.001);
        assertEquals("10.0 - 4.0 = 6.0", subExp.getExpression());

        // 测试负数结果
        AbstractExpression subExp2 = new SubtractExpression(5, 8);
        assertEquals(-3.0, subExp2.getResult(), 0.001);
    }
}
